
package cs2114.antiFingerMines;

//-------------------------------------------------------------------------
/**
*  This class is part of the four other classes that utilizes threads
*  to make the app run faster.
*
*  @author William-Laptop
*  @version Apr 20, 2012
*/
public class MineDistanceThreeb extends Thread
{

	Location finger;
	Mine[] field;
	float closest;

	// ----------------------------------------------------------
    /**
     * Create a new MineDistanceOne object.
     * @param loc the fingers current location
     * @param mines the field of mines
     */
	public MineDistanceThreeb(Location loc, Mine[] mines)
	{
		finger = loc;
		field = mines;
		closest = 99999;
	}

    /**
     * This thread only runs on the first fifth of the mine field and also
     * sets the smallest distance between the finger and the mine to closest
     */
	public void run()
	{
		for (int i = 2*field.length/5; i < 3*field.length/5; i++)
        {
            if (field[i].traversableDistanceBetween(finger) <= closest)
            {
                closest = field[i].traversableDistanceBetween(finger);
            }
        }
	}

    /**
    * This method returns closest so that it can be compared to the closest
    * values returned from the other threads.
    * @return float is the closest mine to the finger in the first fifth
    * of the minefield
    */
	public float getClosest()
	{
		return closest;
	}

}
